<?php
/*
* functii sectiune mijloc
*/
require_once("include/classes/database.php");

function showCenterSectionElements(){
	if(isset($_GET['center'])){
		switch ($_GET['center']){
			case 'newproj':
				showNewProjMenu();
				break;

			case 'view':
				showViewAndEditDocument();
				break;

			case 'openproj':
				showOpenDocument();
				break;
				
			case 'viewAgenda':
				showViewAgendaMenu();
				break;
			case 'export':
				showExportPersonalData();
				break;
			
			case 'chat':
				showMainChat();
				break;
		}
	}
}

function showNewProjMenu(){
	echo("<form id='newProj' action='process.php' method='post'>");
	echo("<input name='subNewProj' type='hidden' value='1' />");
	echo("<table width='75%' align='center'><caption>Proiect nou</caption><tr><td class='newProj'>");

	echo("<div id='divDescr' class='newProjShow'>");
	echo("<table width='100%' border='0' align='center'>");
	echo("<tr><td align='right' width='40%'>Denumire</td>");
	echo("<td align='center'><input id='newProjDenumire' name='newProjDenumire' type='text' maxlength='35' /></td></tr>");
	echo("<tr><td align='right' width='40%'>Tip</td>");
	echo("<td align='center'><select name='newProjType' id='newProjType'>");
	echo("<option value='scientific' selected='selected'>scientific</option>");
	echo("<option value='usual'>usual</option>");
	echo("</select></td></tr>");
	echo("<tr>");
	echo("<td colspan='2' align='right' onclick=\"checkNewProjNext()\">Next-></td>");
	echo("</tr></table>");
	echo("</div>");

	echo("<div id='divAuth' class='newProjHidden'>");
	echo("<table width='100%' border='0' align='center'>");
	echo("<tr><td width='50%' align='center'>Colaboratori:</td>");
	echo("<td align='center'>");
	
	$dom=new DOMDocument();
	$dom->load("xmlDb/agenda.xml");
	$xsl=new DOMDocument();
	$xsl->load("include/xsl/newProjListFriends.xsl");
	$proc=new XSLTProcessor();
	$proc->importStylesheet($xsl);
	$proc->setParameter("", "username", $_SESSION['username']);
	print $proc->transformToXml($dom);
	
	echo("</td></tr>");
	echo("<tr><td align='left' onclick=\"hideDivs('divAuth')\"><-Back</td>");
	echo("<td align='right' onclick=\"submitForm('newProj')\">Finish</td>");
	echo("</tr></table>");
	echo("</div>");
	//echo("</form>");
	echo("</td></tr></table>");
	echo("</form>");
}

function showOpenDocument(){
	//echo("afisare proiecte existente");
	echo("<table width='75%' align='center' class='newProj'><caption align='center'>Proiecte curente</caption>");
	if(isset($_SESSION['activeProjects'])){
		//var_dump($_SESSION['activeProjects']);
		foreach ($_SESSION['activeProjects'] as $prj){
			//echo("<p align='center'>".$prj."</p>");
			echo("<tr><td class='openProject' onclick=\"setOpenDocVar('".$prj."')\">".$prj."</td></tr>");
		}
	}else {
		echo("<tr><td align='center'>Nu exista proiecte pe server</td></tr>");
	}
	//echo("</table>");
	echo("<tr><td class='openProjHideForm'><form id='openServDoc' action='process.php' method='post'>");
	echo("<input name='procOpenServDoc' type='hidden' id='procOpenServDoc' value='1'/></form></td></tr>");
	echo("</table>");
	//echo("<script language='javascript'>showContentPane();</script>");
}

function showViewAndEditDocument(){
	if(isset($_SESSION['docName'])){
		if(isset($_GET['chapter'])){
			echo("<table width='95%' align='center' class='newProj'>");
			echo("<caption align='center'>..::".$_SESSION['docName']."::".$_GET['chapter']."::..  Author: ".$_SESSION['documentInfo'][$_GET['chapter']]['author']."</caption>");
			if($_GET['chapter'] !== "docInfo"){
				if($_SESSION['documentInfo'][$_GET['chapter']]['author'] == $_SESSION['username']){
					printEditorTopMenu();
				}
			}
			echo("<tr><td colspan='9'>");
			//echo("<script language='javascript'>loadDocumentFromUrl('".$_SESSION['docName']."');</script>");
			//echo("<script language='javascript'>showXml();</script>");
			//echo("<div id='helder'><script language='javascript'>showXml();</script></div></td></tr>");
			if($_GET['chapter']=="docInfo"){
				echo("<div id='helder'><script language='javascript'>loadDocumentFromUrl('".$_SESSION['docName']."');</script></div>");
			}else {
				echo("<div id='helder'><script language='javascript'>");
				echo(" cleanHelder();");
				echo(" editorDocument=new xmlDocument('".$_SESSION['docName']."','".$_SESSION['docPath']."'); ");
				echo(" editorDocument.loadChapter('".$_GET['chapter']."'); ");
				if($_SESSION['documentInfo'][$_GET['chapter']]['author'] == $_SESSION['username']){
					echo(" editorDocument.docElements['".$_GET['chapter']."'].printToHtmlForAuthor(editorDocument.docName); ");
				}else {
					echo(" editorDocument.docElements['".$_GET['chapter']."'].printToHtmlForFriend(editorDocument.docName, '".$_SESSION['username']."'); ");
					echo(" friendlyComments=new xmlChapterComments('".$_GET['chapter']."', '".$_SESSION['docPath']."/".$_GET['chapter']."Comments.xml');");
				}
				echo("</script></div>");
			}
			echo("</td></tr></table>");

			//div's pt screen freez
			echo("<div id='screenFreeze_screen' class='screenFreeze_screen'></div>");
			echo("<div id='screenFreeze_panel' style='display:none;' class='screenFreeze_panel'>");
			echo("<p align='center'><img src='include/images/loading.gif' width='32' height='32'/></p>");
			echo("<p align='center' onclick=\"saveChapterChangesEnd('".$_GET['chapter']."');\"><b>Va rugam asteptati! Se salveaza documentul...</b></p>");
			echo("<p align='center' id='serverResponseHelder'></p>");
			echo("<div id='empty' style='background-color:#cccccc;border:1px solid black;height:30px;width:300px;padding:0px;' align='left'>");
			echo("<div id='progressBar2' style='position:relative;top:0px;left:0px;background-color:#333333;height:30px;width:0px;padding-top:5px;padding:0px;'>");
			echo("<div id='progressBar1' style='position:relative;top:0px;left:0px;color:#f0ffff;height:30px;text-align:center;font:bold;padding:0px;padding-top:5px;'>");
			echo("</div></div></div</div>");
			printEditorInnerElementsDivs();
		}
	}
	echo("<script language='javascript'>showContentPane();</script>");
}

function printEditorTopMenu(){
	echo("<tr><td class='editor' onclick=\"openNewParaPanel()\">Paragraf</td>");
	echo("<td class='editor' onclick=\"openNewNotePanel()\">Nota</td>");
	echo("<td class='editor'>Citat</td>");
	echo("<td class='editor'>Imagine</td>");
	echo("<td class='editor' onclick=\"openNewTablePanel()\">Tabel</td>");
	echo("<td class='editor'>Lista</td>");
	echo("<td class='editor'>Atentionare</td><td class='editor'>Subcapitol</td><td class='editor'>Sectiune</td>");
	echo("</tr><tr><td class='editor' colspan='9' align='center' onclick=\"saveChapterChanges('".$_GET['chapter']."');\"> <b>..::</b>Salvare modificari<b>::..</b></tr>");
}

function printEditorInnerElementsDivs(){
	//creare pragraf nou
	echo("<div id='editorElements_panel' style='display:none;' class='screenFreeze_panel'>");
	echo("<form action='#' method='get' name='createNewParaForm'>");
	echo("<table width='250' border='0'><caption align='top'>Creare Paragraf Nou</caption>");
	echo("<tr><td colspan='3'><textarea name='createNewParaTextarea' id='createNewParaTextarea' cols='65' rows='15'></textarea></td></tr>");
	echo("<tr><td class='editor'><input type='button' value='    Ok   ' onclick=\"newParagraphOk('".$_GET['chapter']."')\"/></td>");
	echo("<td class='editor'><input type='reset' /></td>");
	echo("<td class='editor'><input type='button' value=' Cancel ' onclick=\"newParagraphCancel()\"/></td></tr>");
	echo("</table></form>");
	echo("</div>");
	
	//creare pragraf nou
	echo("<div id='editorElementsNote_panel' style='display:none;' class='screenFreeze_panel'>");
	echo("<form action='#' method='get' name='createNewNoteForm'>");
	echo("<table width='250' border='0'><caption align='top'>Creare Nota Noua</caption>");
	echo("<tr><td colspan='3'><textarea name='createNewNoteTextarea' id='createNewNoteTextarea' cols='65' rows='15'></textarea></td></tr>");
	echo("<tr><td class='editor'><input type='button' value='    Ok   ' onclick=\"newNoteOk('".$_GET['chapter']."')\"/></td>");
	echo("<td class='editor'><input type='reset' /></td>");
	echo("<td class='editor'><input type='button' value=' Cancel ' onclick=\"newNoteCancel()\"/></td></tr>");
	echo("</table></form>");
	echo("</div>");
	
	//creare tabel nou
	echo("<div id='editorElementsTable_panel' style='display:none;' class='screenFreeze_panel'>");
	echo("<table width='350' border='0'>");
	echo("<caption align='top'>Creare Tabel Nou</caption>");
	
	echo("<tr><td><div align='center' id='createNewTableEditorP1' class='createNewTableWinShow'>");
	echo("<table width='100%' border='0'><tr>");
	echo("<td align='center'>Titlu</td>");
	echo("<td><input type='text' size='15' id='createNewTableCaption' name='createNewTableCaption' onfocus=\"this.style.backgroundColor='#CCFFFF'\" onblur=\"this.style.backgroundColor='#ffffff'\"/>");
	echo("</tr><tr><td>Numar coloane</td>");
	echo("<td><input type='text' size='3' id='createNewTableRowsNr' name='createNewTableRowsNr' onfocus=\"this.style.backgroundColor='#CCFFFF'\" onblur=\"this.style.backgroundColor='#ffffff'\"/>");
	echo("</td></tr><tr><td align='center' colspan='2' onclick=\"createNewTableValidatePage1();\">Next >>></td></tr>");
	echo("<tr><td colspan='2'><input type='hidden' id='createNewTableChapterName' value='".$_GET['chapter']."'/></td></tr>");
	echo("</table></div>");
	
	echo("<div align='center' id='createNewTableEditorP2' class='createNewTableWinHide'>");
	echo("<table width='100%' border='0'>");
	echo("</table></div></td></tr></table></div>");
	
	//create comment
	echo("<div id='editorElementsComment_panel' style='display:none;' class='screenFreeze_panel'>");
	echo("<form action='#' method='get' name='createNewCommentForm'>");
	echo("<table width='250' border='0'><caption align='top'>Creare Comentariu Nou</caption>");
	echo("<tr><td colspan='3'><textarea name='createNewCommentTextarea' id='createNewCommentTextarea' cols='65' rows='15'></textarea></td></tr>");
	echo("<tr><td class='editor'><input type='button' value='    Ok   ' onclick=\"createNewCommentOk('".$_GET['chapter']."')\"/></td>");
	echo("<td class='editor'><input type='hidden' id='commentElementId' value=''/><input type='reset' /></td>");
	echo("<td class='editor'><input type='button' value=' Cancel ' onclick=\"createNewCommentCancel()\"/></td></tr>");
	echo("</table></form>");
	echo("</div>");
}

function showViewAgendaMenu(){
	echo("<table align='center' class='agendaFrame'><tr>");
	//stanga
	echo("<td class='agendaStanga'>");
	$dom=new DOMDocument();
	$dom->load("xmlDb/agenda.xml");
	$xsl=new DOMDocument();
	$xsl->load("include/xsl/agendaListFriends.xsl");
	$proc=new XSLTProcessor();
	$proc->importStylesheet($xsl);
	//$domParams=array()
	$proc->setParameter("", "username", $_SESSION['username']);
	print $proc->transformToXml($dom);
	echo("</td>");
	//centru
	echo("<td><div id='agendaHelder'>");
	echo("</div></td>");
	echo("</tr></table>");	
}

function showExportPersonalData(){
	echo("<fieldset class='exportVcard' align='center'><legend>VCard</legend>");
	echo("<div>");
	$dom=new DOMDocument();
	$dom->load("xmlDb/agenda.xml");
	$xsl=new DOMDocument();
	$xsl->load("include/xsl/agendaVCard.xsl");
	$proc=new XSLTProcessor();
	$proc->importStylesheet($xsl);
	$proc->setParameter("", "username", $_SESSION['username']);
	print $proc->transformToXml($dom);
	echo("</div>");
	echo("</fieldset>");
}

function showMainChat(){
	echo"chat";
}
?>